package com.gxa.service.commserve.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gxa.entity.commserve.ComplaintsSuggestions;
import com.gxa.dto.commservedto.ComplaintsSuggestionsSearchCriteria;
import com.gxa.mapper.commserve.ComplaintsSuggestionsMapper;
import com.gxa.service.commserve.ComplaintsSuggestionsService;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:18:00
 */
@Service
public class ComplaintsSuggestionsServiceImpl extends ServiceImpl<ComplaintsSuggestionsMapper, ComplaintsSuggestions> implements ComplaintsSuggestionsService {

    @Autowired
    private ComplaintsSuggestionsMapper complaintsSuggestionsMapper;

    @Override
    public Map<String, Object> queryList(Integer pageNum, Integer pageSize) {
        Map<String,Object> map = new HashedMap();
        QueryWrapper<ComplaintsSuggestions> queryWrapper = new QueryWrapper<>();
        Page<ComplaintsSuggestions> page = PageHelper.startPage(pageNum,pageSize);
        List<ComplaintsSuggestions> complaintsSuggestionsList = this.complaintsSuggestionsMapper.selectList(queryWrapper);
        PageInfo<ComplaintsSuggestions> pageInfo = new PageInfo<>(complaintsSuggestionsList);
        map.put("pageInfo",pageInfo);
        return map;

    }

    @Override
    public void add(ComplaintsSuggestions complaintsSuggestions) {
        this.complaintsSuggestionsMapper.insert(complaintsSuggestions);

    }

    @Override
    public Map<String, Object> queryListBySearch(ComplaintsSuggestionsSearchCriteria complaintsSuggestionsSearchCriteria, Integer pageNum, Integer pageSize) {
        Map<String,Object> map = new HashedMap();
        QueryWrapper<ComplaintsSuggestions> queryWrapper = new QueryWrapper<>();
        if (complaintsSuggestionsSearchCriteria.getComplainant()!=null){
            queryWrapper.like("complainant",complaintsSuggestionsSearchCriteria.getComplainant());
        }
        if (complaintsSuggestionsSearchCriteria.getContactNumber()!=null){
            queryWrapper.like("contact_number",complaintsSuggestionsSearchCriteria.getContactNumber());
        }
        if (complaintsSuggestionsSearchCriteria.getSuggestionType()!=null){
            queryWrapper.like("suggestion_type",complaintsSuggestionsSearchCriteria.getSuggestionType());
        }
        if (complaintsSuggestionsSearchCriteria.getState()!=null){
            queryWrapper.like("state",complaintsSuggestionsSearchCriteria.getState());
        }
        if (complaintsSuggestionsSearchCriteria.getStartTime()!=null&&!complaintsSuggestionsSearchCriteria.getEndTime().equals("")){
           queryWrapper.between("suggested_time",complaintsSuggestionsSearchCriteria.getStartTime(),complaintsSuggestionsSearchCriteria.getEndTime());
       }
        Page<ComplaintsSuggestions> page = PageHelper.startPage(pageNum,pageSize);
        List<ComplaintsSuggestions> complaintsSuggestionsList = this.complaintsSuggestionsMapper.selectList(queryWrapper);
        PageInfo<ComplaintsSuggestions> pageInfo = new PageInfo<>(complaintsSuggestionsList);
        map.put("pageInfo",pageInfo);
        return map;
    }
}
